AOMedia AV1 Codec
bitstream.h
1/*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#ifndef AOM_AV1_ENCODER_BITSTREAM_H_
13#define AOM_AV1_ENCODER_BITSTREAM_H_
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19#include <stdbool.h>
20
21#include "av1/common/av1_common_int.h"
22#include "av1/common/blockd.h"
23#include "av1/common/enums.h"
24#include "av1/encoder/level.h"
25#include "aom_dsp/bitwriter.h"
26#include "aom_util/aom_pthread.h"
27
28struct aom_write_bit_buffer;
29struct AV1_COMP;
30struct ThreadData;
31
34// Stores the location and size of a tile's data in the bitstream. Used for
35// later identifying identical tiles
36typedef struct {
37 uint8_t *data;
38 size_t size;
39} TileBufferEnc;
40
41typedef struct {
42 uint8_t *frame_header;
43 size_t obu_header_byte_offset;
44 size_t total_length;
45} FrameHeaderInfo;
46
47typedef struct {
48 struct aom_write_bit_buffer *saved_wb; // Bit stream buffer writer structure
49 TileBufferEnc buf; // Structure to hold bitstream buffer and size
50 uint32_t *total_size; // Size of the bitstream buffer for the tile in bytes
51 uint8_t *dst; // Base address of tile bitstream buffer
52 uint8_t *tile_data_curr; // Base address of tile-group bitstream buffer
53 size_t tile_buf_size; // Available bitstream buffer for the tile in bytes
54 uint8_t obu_extn_header; // Presence of OBU extension header
55 uint32_t obu_header_size; // Size of the OBU header
56 int curr_tg_hdr_size; // Size of the obu, tg, frame headers
57 int tile_size_mi; // Tile size in mi units
58 int tile_row; // Number of tile rows
59 int tile_col; // Number of tile columns
60 int is_last_tile_in_tg; // Flag to indicate last tile in a tile-group
61 int new_tg; // Flag to indicate starting of a new tile-group
62} PackBSParams;
63
64typedef struct {
65 uint64_t abs_sum_level;
66 uint16_t tile_idx;
67} PackBSTileOrder;
68
69// Pack bitstream data for pack bitstream multi-threading.
70typedef struct {
71#if CONFIG_MULTITHREAD
72 // Mutex lock used while dispatching jobs.
73 pthread_mutex_t *mutex_;
74#endif
75 // Tile order structure of pack bitstream multithreading.
76 PackBSTileOrder pack_bs_tile_order[MAX_TILES];
77
78 // Index of next job to be processed.
79 int next_job_idx;
80 // Initialized to false, set to true by the worker thread that encounters an
81 // error in order to abort the processing of other worker threads.
82 bool pack_bs_mt_exit;
83} AV1EncPackBSSync;
84
87// Writes only the OBU Sequence Header payload, and returns the size of the
88// payload written to 'dst'. This function does not write the OBU header, the
89// optional extension, or the OBU size to 'dst'.
90uint32_t av1_write_sequence_header_obu(const SequenceHeader *seq_params,
91 uint8_t *const dst);
92
93// Writes the OBU header byte, and the OBU header extension byte when
94// has_nonzero_operating_point_idc is true and the OBU is part of a frame.
95// Returns number of bytes written to 'dst'.
96uint32_t av1_write_obu_header(AV1LevelParams *const level_params,
97 int *frame_header_count, OBU_TYPE obu_type,
98 bool has_nonzero_operating_point_idc,
99 int obu_extension, uint8_t *const dst);
100
101int av1_write_uleb_obu_size(size_t obu_header_size, size_t obu_payload_size,
102 uint8_t *dest);
103
104// Pack tile data in the bitstream with tile_group, frame
105// and OBU header.
106void av1_pack_tile_info(struct AV1_COMP *const cpi, struct ThreadData *const td,
107 PackBSParams *const pack_bs_params);
108
109void av1_write_last_tile_info(
110 struct AV1_COMP *const cpi, const FrameHeaderInfo *fh_info,
111 struct aom_write_bit_buffer *saved_wb, size_t *curr_tg_data_size,
112 uint8_t *curr_tg_start, uint32_t *const total_size,
113 uint8_t **tile_data_start, int *const largest_tile_id,
114 int *const is_first_tg, uint32_t obu_header_size, uint8_t obu_extn_header);
115
121int av1_pack_bitstream(struct AV1_COMP *const cpi, uint8_t *dst, size_t *size,
122 int *const largest_tile_id);
123
124void av1_write_tx_type(const AV1_COMMON *const cm, const MACROBLOCKD *xd,
125 TX_TYPE tx_type, TX_SIZE tx_size, aom_writer *w);
126
127void av1_reset_pack_bs_thread_data(struct ThreadData *const td);
128
129void av1_accumulate_pack_bs_thread_data(struct AV1_COMP *const cpi,
130 struct ThreadData const *td);
131
132void av1_write_obu_tg_tile_headers(struct AV1_COMP *const cpi,
133 MACROBLOCKD *const xd,
134 PackBSParams *const pack_bs_params,
135 const int tile_idx);
136
137int av1_neg_interleave(int x, int ref, int max);
138#ifdef __cplusplus
139} // extern "C"
140#endif
141
142#endif // AOM_AV1_ENCODER_BITSTREAM_H_
OBU_TYPE
OBU types.
Definition aom_codec.h:546
int av1_pack_bitstream(struct AV1_COMP *const cpi, uint8_t *dst, size_t *size, int *const largest_tile_id)
Pack the bitstream for one frame.
Top level common structure used by both encoder and decoder.
Definition av1_common_int.h:757
Top level encoder structure.
Definition encoder.h:2866
Variables related to current coding block.
Definition blockd.h:570